<?php

namespace app\admin\model\wanlshop;

use think\Model;
use traits\model\SoftDelete;

class Pay extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'wanlshop_pay';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'pay_type_text',
        'pay_state_text',
        'status_text',
        'is_commission_text',
        'audit_status_text'
    ];
    

    
    public function getPayTypeList()
    {
        return ['0' => __('Pay_type 0'), '1' => __('Pay_type 1'), '2' => __('Pay_type 2'), '4' => __('Pay_type 4'), '5' => __('Pay_type 5'), '6' => __('Pay_type 6')];
    }

    public function getPayStateList()
    {
        return ['0' => __('Pay_state 0'), '1' => __('Pay_state 1'), '2' => __('Pay_state 2')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }

    public function getIsCommissionList()
    {
        return ['0' => __('Is_commission 0'), '1' => __('Is_commission 1')];
    }

    public function getAuditStatusList()
    {
        return ['0' => __('Audit_status 0'), '1' => __('Audit_status 1'), '2' => __('Audit_status 2')];
    }


    public function getPayTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['pay_type'] ?? '');
        $list = $this->getPayTypeList();
        return $list[$value] ?? '';
    }


    public function getPayStateTextAttr($value, $data)
    {
        $value = $value ?: ($data['pay_state'] ?? '');
        $list = $this->getPayStateList();
        return $list[$value] ?? '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }


    public function getIsCommissionTextAttr($value, $data)
    {
        $value = $value ?: ($data['is_commission'] ?? '');
        $list = $this->getIsCommissionList();
        return $list[$value] ?? '';
    }


    public function getAuditStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['audit_status'] ?? '');
        $list = $this->getAuditStatusList();
        return $list[$value] ?? '';
    }




    public function shop()
    {
        return $this->belongsTo('Shop', 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function receive()
    {
        return $this->belongsTo('app\admin\model\User', 'receive_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
